//
//  LightingViewController.m
//  bluetoothLamp
//
//  Created by sunx on 14/12/12.
//  Copyright (c) 2014年 sunx. All rights reserved.
//

#import "LightingViewController.h"
#import "NavigationController.h"
@interface LightingViewController ()
{
    int frameHeight;
    int frameWidth;
    UIImage *on;
    UIImage *off;
    ViewController *viewController;
    NavigationController *navigationController;
}
@end

@implementation LightingViewController

@synthesize toggleViewBaseChange;
- (void)viewDidLoad {
    [super viewDidLoad];
    
    navigationController = (NavigationController *)[self parentViewController];
    viewController = (ViewController*)[[self parentViewController]presentingViewController];
    
    
    self.navigationItem.hidesBackButton = YES;
    self.navigationController.navigationBar.hidden = YES;
    
    on = [UIImage imageNamed:@"on"];
    off = [UIImage imageNamed:@"off"];
    
    CGRect frame = [ UIScreen mainScreen ].bounds;
    CGSize size = frame.size;
    
    toggleViewBaseChange = [[ToggleView alloc]initWithFrame:CGRectMake(0,size.height *0.7, size.width, 75) toggleViewType:ToggleViewTypeNoLabel toggleBaseType:ToggleBaseTypeChangeImage toggleButtonType:ToggleButtonTypeDefault];
    
    toggleViewBaseChange.toggleDelegate = self;
    
    [toggleViewBaseChange setSelectedButton:ToggleButtonSelectedRight];
    
    [self.view addSubview:toggleViewBaseChange];
    
}

- (void)viewWillDisappear:(BOOL)animated {
    [toggleViewBaseChange setSelectedButton:ToggleButtonSelectedLeft];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (IBAction)press1:(id)sender {    
    [viewController level_1];
    NSLog(@"2");
    [_button1 setImage:on forState:UIControlStateNormal];
    [_button2 setImage:off forState:UIControlStateNormal];
    [_button3 setImage:off forState:UIControlStateNormal];
    
}
- (IBAction)press2:(id)sender {
    [viewController level_2];
    [_button1 setImage:on forState:UIControlStateNormal];
    [_button2 setImage:on forState:UIControlStateNormal];
    [_button3 setImage:off forState:UIControlStateNormal];
}
- (IBAction)press3:(id)sender {
    [viewController level_3];
    [_button1 setImage:on forState:UIControlStateNormal];
    [_button2 setImage:on forState:UIControlStateNormal];
    [_button3 setImage:on forState:UIControlStateNormal];
}
- (IBAction)buttonPressed:(id)sender {
    [toggleViewBaseChange setSelectedButton:ToggleButtonSelectedLeft];
}


- (void)selectLeftButton
{
    NSLog(@"LeftButton Selected");
    [viewController turnOn];
    [_button1 setImage:on forState:UIControlStateNormal];
}

- (void)selectRightButton
{
    NSLog(@"RightButton Selected");
    [viewController turnOff];
    [_button1 setImage:off forState:UIControlStateNormal];
    [_button2 setImage:off forState:UIControlStateNormal];
    [_button3 setImage:off forState:UIControlStateNormal];

}

- (IBAction)back:(id)sender {
    [navigationController isConnected];
}
- (IBAction)exitToHere:(UIStoryboardSegue *)sender {
}

@end
